<!-- 确认对话框模态框 -->
<div class="modal fade" id="confirmModal" tabindex="-1" aria-labelledby="confirmModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="confirmModalLabel">
                    <i class="bi bi-exclamation-triangle-fill text-warning me-2"></i>
                    确认操作
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="关闭"></button>
            </div>
            <div class="modal-body" id="confirmModalBody">
                您确定要执行此操作吗？此操作可能无法撤销。
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                    <i class="bi bi-x-circle me-1"></i>取消
                </button>
                <button type="button" class="btn btn-danger" id="confirmModalConfirm">
                    <i class="bi bi-check-circle me-1"></i>确认
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 确认对话框脚本 -->
<script>
document.addEventListener('DOMContentLoaded', function() {
    const confirmModal = new bootstrap.Modal(document.getElementById('confirmModal'));
    const confirmModalBody = document.getElementById('confirmModalBody');
    const confirmModalConfirm = document.getElementById('confirmModalConfirm');

    // 处理确认按钮点击
    document.addEventListener('click', function(e) {
        const confirmBtn = e.target.closest('[data-confirm]');
        if (confirmBtn) {
            e.preventDefault();

            const message = confirmBtn.getAttribute('data-confirm') || '您确定要执行此操作吗？';
            const href = confirmBtn.getAttribute('href') || confirmBtn.getAttribute('data-href');
            const form = confirmBtn.closest('form');

            confirmModalBody.textContent = message;

            confirmModalConfirm.onclick = function() {
                if (form) {
                    form.submit();
                } else if (href) {
                    window.location.href = href;
                }
                confirmModal.hide();
            };

            confirmModal.show();
        }
    });
});
</script>